import { ORDERS } from "../../config";
import { Event } from "../../utils/interface";
import { observer } from "../../utils/observer";

let tabsList = ["全部", "待付款", "代发货", "退款/退货"];

interface Order {
  order_number: string;
  total_price: number;
  create_time: number | string;
}

let orders: Array<Order> = [];

let currentOrders: Array<Order> = orders;

let data = {
  tabsList,
  orders,
  currentOrders,
};
Page({
  data,
  onLoad() {
    data = observer(this.data, this);
    this.selectAllComponents("");
    this.init();
  },
  init() {
    data.orders = wx.getStorageSync(ORDERS);
    data.currentOrders = data.orders;
  },
  change(e: Event<unknown>) {
    const str = e.detail as unknown as string;
    const len = data.orders.length;
    switch (str) {
      case "全部":
        data.currentOrders = [...data.orders];
        break;
      case "待付款":
        data.currentOrders = [...data.orders].slice(len * 0.5);
        console.log(data.currentOrders.length);
        break;
      case "代发货":
        data.currentOrders = [...data.orders].slice(len * 0.7);
        console.log(data.currentOrders.length);
        break;
      case "退款/退货":
        data.currentOrders = [...data.orders].slice(len * 0.9);
        console.log(data.currentOrders.length);

        break;
    }
  },
});
